Count how many times a trigger has been actived.

Good Morning!

I'm having trouble making a dxl to count how many times a particular trigger has been activated.
I tried to put a counter inside the trigger itself, but what happened was the counter appeared several times, instead of one with the end result of my count.
Can someone give me a suggestion.

Object o = current
Trigger T = current
string status = (value T)
int count = 0

if(o."Change ID" "" ==  ""){
        if (status "" != ""){
                count++
                ack "CHANGE INFO: Requisitos que foram atualizados cujo o CCID estava previamente vazio " count""
                set (trigPreConPass)
        }
}

One little observation, the code above is from a pre-condition trigger.

But I think I will choose a post condition trigger.


Thank you!


braolive - Sat Feb 02 07:32:39 EST 2019

Re: Count how many times a trigger has been actived.
morast - Thu Feb 07 05:21:27 EST 2019

Maybe you can let your trigger code make the counting in a file.

Re: Count how many times a trigger has been actived.
Mathias Mamsch - Tue Feb 12 05:11:02 EST 2019

I guess it depends on what you want. If you want to count the invocations during one session (inside one client, while the module is opened) you might get away with a (nother) dynamic trigger, since the code of the trigger lives in the same code as it was installed. So you should be able to do

int count = 0

void func(Trigger T) {
    count++
}

trigger(..., func)

If you want to count every invocation by every client between the sessions, then you should use an external storage. The exact realization probably depends on your use case, how often the trigger is involved, what exactly you want to count, etc. From the code you posted it does not seem to be time critical so using the Config Area to store the counter in a file seems reasonable. Not sure this helps a lot, regards, Mathias